<?php
/**
 * 我的足迹模型
 *
 * 
 *
 *
 * @copyright  Copyright (c) 2007-2013 ShopNC Inc. (http://www.shopnc.net)
 * @license    http://www.shopnc.net
 * @link       http://www.shopnc.net
 * @since      File available since Release v1.1
 */
defined('InShopNC') or exit('Access Invalid!');
class goodsbrowseModel extends Model{

    public function __construct(){
        parent::__construct('goodsbrowse');
    }

	/*
	 * 构造条件
	 */
	private function getCondition($condition){
		$condition_str = '' ;
        if(!empty($condition['member_id'])) {
            $condition_str.= " and  member_id = '{$condition['member_id']}'";
        }
		return $condition_str;
    }
	/*
	 *  获得列表
	 *  @param array $condition
	 *  @param obj $page 	//分页对象
	 *  @return array
	 */
	public function getGoodsBrowseList($condition='',$page='') {
        $param = array() ;
        $param['table'] = 'goods_browse' ;
        $param['where'] = $this->getCondition($condition);
        $param['order'] = 'browsetime desc ';
        return Db::select($param,$page);
	}

	/**
	 * 删除
	 *
	 * @param int $id 记录ID
	 * @return array $rs_row 返回数组形式的查询结果
	 */
	public function delGoodsBrowse($condition){
		if (empty($condition)){
			return false;
		}
		$condition_str = '';	
		if ($condition['goods_id'] != ''){
			$condition_str .= " and goods_id='{$condition['goods_id']}' ";
		}
		if ($condition['member_id'] != ''){
			$condition_str .= " and member_id='{$condition['member_id']}' ";
		}
		return Db::delete('goods_browse',$condition_str);
	}

    /**
     * 检查是否存在
     * @param array $update 更新数据
     * @param array $condition 条件
     * @return boolean
     */
    public function getGoodsBrowseInfo($condition) {
        return $this->table('goods_browse')->where($condition)->find();
    }

    /**
     * 更新足迹数据
     * 
     * @param array $update 更新数据
     * @param array $condition 条件
     * @return boolean
     */
    public function updateGoodsbrowse($update, $condition) {
        return $this->table('goods_browse')->where($condition)->update($update);
    }

    /**
     * 新增足迹数据
     * 
     * @param array $insert 数据
     * @param string $table 表名
     */
    public function addGoodsbrowse($insert, $table = "goods_browse") {
        return $this->table($table)->insert($insert);
    }

}
